package com.wc.AlgoOJ.DS0301;

import java.io.PrintWriter;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/1/22 19:37
 * @description 遍历完全二叉树
 * http://43.138.190.70:8888/p/DS0301
 */
public class Main {
    static int n;
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        dfsQ(1);
        out.println();
        dfsZ(1);
        out.println();
        dfsH(1);
        out.println();
        out.flush();
    }

    static void dfsQ(int x) {
        if (x > n) return;
        out.print(x + " ");
        dfsQ(x << 1);
        dfsQ(x << 1 | 1);
    }
    static void dfsZ(int x) {
        if (x > n) return;
        dfsZ(x << 1);
        out.print(x + " ");
        dfsZ(x << 1 | 1);
    }
    static void dfsH(int x) {
        if (x > n) return;
        dfsH(x << 1);
        dfsH(x << 1 | 1);
        out.print(x + " ");
    }
}


